﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Text;

namespace Sitecore.Helpers
{
    public static class PageNavigator
    {
        public static MvcHtmlString PageNavigation(this HtmlHelper helper, string ViewName, int pageNumber, int itemsCount, int pageSize)
        {
            StringBuilder sb = new StringBuilder();
            if (pageNumber > 0)
            {
                sb.Append(helper.ActionLink("previous", ViewName, new { PageNumber = pageNumber - 1 }));
            }
            else
            { 
            sb.Append("previous");
            }
            sb.Append("&nbsp");
            int pageCount = (int)Math.Ceiling((double)itemsCount / pageSize);
            if (pageNumber < pageCount - 1)
            {
                sb.Append(helper.ActionLink("next", ViewName, new { PageNumber = pageNumber + 1 }));
            }
            else 
            {
                sb.Append("next");
            }
            return MvcHtmlString.Create( sb.ToString());
        }
    }
}